<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../../base.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据 - AdminLTE2定制版</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
</head>
<body>
<div id="frameContent" class="content-wrapper" style="margin-left:0px;">
<section class="content-header">
    <h1>
        系统管理
        <small>部门管理</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
    </ol>
</section>
<!-- 内容头部 /-->

<!-- 正文区域 -->
<section class="content">

    <!-- .box-body -->
    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">部门列表</h3>
        </div>

        <div class="box-body">

            <!-- 数据表格 -->
            <div class="table-box">

                <!--工具栏-->
                <div class="pull-left">
                    <div class="form-group form-inline">
                        <div class="btn-group">
                            <button type="button" class="btn btn-default" title="新建" onclick='location.href="${ctx}/system/dept/toAdd.do"'><i class="fa fa-file-o"></i> 新建</button>
                            <button type="button" class="btn btn-default" title="删除" onclick='deleteById()'><i class="fa fa-trash-o"></i> 删除</button>
                            <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                        </div>
                    </div>
                </div>
                <div class="box-tools pull-right">
                    <jsp:include page="../../common/search.jsp">
                        <jsp:param name="pageUrl" value="${ctx}/system/dept/list.do"/>
                    </jsp:include>
                </div>
                <!--工具栏/-->

                <!--数据列表-->
                <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                    <thead>
                    <tr>
                        <th class="" style="padding-right:0px;">
                            <input type="checkbox" name="selid" onclick="checkAll('id', this)">
                        </th>
                        <th class="sorting">序号</th>
                        <th class="sorting">编号</th>
                        <th class="sorting">上级</th>
                        <th class="sorting">名称</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageBean.data}" var="dept" varStatus="st">
                        <tr>
                            <td><input type="checkbox" name="id" value="${dept.deptId}"/></td>
                            <td>${st.count}</td>
                            <td>${dept.deptId}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${dept.parent != null}">
                                        <a href="${ctx}/system/dept/toUpdate.do?id=${dept.parent.deptId}">${dept.parent.deptName}</a>
                                    </c:when>
                                    <c:otherwise>
                                        无上级部门
                                    </c:otherwise>
                                </c:choose>
                            </td>
                            <td>${dept.deptName}</td>
                            <td class="text-center">
                                <button type="button" class="btn bg-olive btn-xs" onclick='location.href="${ctx}/system/dept/toUpdate.do?id=${dept.deptId}"'>编辑</button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="box-footer">
            <jsp:include page="../../common/page.jsp">
                <jsp:param value="${ctx}/system/dept/list.do" name="pageUrl"/>
            </jsp:include>
        </div>
    </div>
    </section>
    <script>
        function checkAll(name, checkbox) {
            var checked = checkbox.checked;
            var checkboxes = document.getElementsByName(name);
            for (var index = 0; index < checkboxes.length; index++) {
                checkboxes[index].checked = checked;
            }
        }

        function deleteById() {
            var ids = getCheckIds(); // 获取所有被选中的复选框的值
            if (ids.length > 0) { // 确保至少勾选了一个复选框
                // 使用 confirm 弹出确认对话框
                if (confirm("确认删除以下ID的公司吗？\n" + ids.join(","))) {
                    // 如果用户点击“确定”，执行删除操作
                    location.href = "${ctx}/system/dept/delete.do?ids=" + ids.join(",");
                }
                // 如果用户点击“取消”，什么也不做
            } else {
                alert("请勾选待处理的记录");
            }
        }

        function getCheckIds() {
            var checkedValues = [];
            $("input:checkbox:checked").each(function () {
                checkedValues.push($(this).val());
            });
            return checkedValues;
        }

    </script>
</div>
</body>
</html>